"""Debug solver to see what's happening."""
import sys
import numpy as np
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.parent))

from src.reproduct_paper.problems.advection import advection_1d_reference
from src.reproduct_paper.advection_solver import AdvectionSolver

problem = advection_1d_reference()

# Very simple test
solver = AdvectionSolver(
    x_domain=problem["domain_x"],
    t_final=1.0,
    num_time_blocks=1,
    num_subdomains_x=2,
    num_subdomains_t=1,
    collocation_x=5,
    collocation_t=5,
    hidden_width=50,
    rand_magnitude=1.0,
    wave_speed=problem["wave_speed"],
    initial_condition=problem["initial_condition"],
    exact_solution=problem["exact_solution"],
    rng=np.random.default_rng(1),
)

results = solver.solve()

# Evaluate at some points
x_test = np.array([0.0, 1.25, 2.5, 3.75, 5.0])
t_test = np.array([0.0, 0.5, 1.0])

print("Testing evaluation:")
for t in t_test:
    print(f"\nAt t={t}:")
    for x in x_test:
        u_num = solver.evaluate_solution(np.array([x]), np.array([t]))[0, 0]
        u_exact = problem["exact_solution"](np.array([x]), np.array([t]))[0, 0]
        print(f"  x={x:.2f}: numerical={u_num:.6f}, exact={u_exact:.6f}, error={abs(u_num-u_exact):.6f}")
